import numpy as np
import time
from precision_data import fp
from structured_mesh import *

# clock
clock_begin = time.perf_counter()    # 定义开始时间

# main codes

dim = 2    # 问题维度
ncx = 64   # x方向单元数量
ncy = 64   # y方向单元数量
ncz = 1    # z方向单元数量

# 每个方向上的范围限定
xmin = fp(0.0)
xmax = fp(0.833)
ymin = fp(0.0)
ymax = fp(0.83)
zmin = fp(0.0)
zmax = fp(1.0)

# 创建网格
case = StructureMesh()
case.CreateMesh(dim, ncx, ncy, ncz)
case.CreateCoordinates(xmin, xmax, ymin, ymax, zmin, zmax)
case.CreateFieldMeshData()

tref = fp(373.0)
case.SetInitialT(tref)

case.CreateCoeffMeshData()

case.CreateSimulationData()

nsteps = 2000        # 迭代步
case.Set_nsteps(nsteps)

case.CreateSolvingMethodData()

niter_t = 100
relax_t = fp(0.75)
res_t   = fp(0.01)
temp_tol = fp(1.e-6)
case.Set_temp_solver_param(niter_t, relax_t, res_t, temp_tol)

fluid = Fluid(ncx, ncy, ncz)
dens  = fp(1.0)
mu    = fp(0.001)
fluid.SetInitialDenMu(dens, mu)

con = fp(81.0)     # 热传导系数
spht = fp(1.0)     # 比热
fluid.Set_con_spht(con, spht)

fluidboundary = FluidBoundary(dim)

# 对于某个单元的每一个面，设置它的边界条件


post = PostProcessing()
post.WriteVTKCollocated_temp(case)

elapsed_time = time.perf_counter() - clock_begin
print('elapsed time: ', elapsed_time)          # 输出总共消耗的时间
